/*
 * @Description  : 借阅单
 * @Author       : zhao
 * @Date         : 2022-07-25 15:06:38
 * @LastEditors  : zhao
 * @LastEditTime : 2023-01-17 08:43:51
 */
import { defineStore } from 'pinia';
import { ElMessage } from 'element-plus'
import {
    CSGetBorrowingForm,
    CSGetBorrowingFormNoApproved,
    CSGetBorrowingFormDetailsSave,
    DownloadFormDetailExcel,
    CSDeleteBorrowingFormDetails,
    CSGetBorrowingFormOverdue,
    CSGetBorrowingFormBtnFinish,
    CSGetBorrowingFormFinish,
    CSGetBorrowingFormDetails,
    CSGetBorrowingFormBtnPass,
    CSGetBorrowingFormBtnReject,
    GetWorkCompany,
    CSGetBorrowingFormReject,
    CSGetBorrowingFormDetailsReject
} from "/@/api/borrow.js"
export const useBorrow = defineStore('borrow', {
    state: () => ({
        downloadObj: {},//下载传参
    }),
    actions: {

        // 借阅单 查询--待审批
        async CSGetBorrowingForm(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingForm(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "借阅单待审批查询失败")
                        reject(res)
                    }

                })

            })

        },
        // 借阅单 查询--已审批
        async CSGetBorrowingFormNoApproved(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormNoApproved(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "借阅单已审批查询失败")
                        reject(res)
                    }

                })

            })

        },
        // 借阅单 已完成
        async CSGetBorrowingFormFinish(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormFinish(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "借阅单已完成查询失败")
                        reject(res)
                    }

                })

            })

        },
        // 借阅单 完成
        async CSGetBorrowingFormBtnFinish(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormBtnFinish(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {

                        reject(res)
                    }

                })

            })

        },
        // 借阅单 完成
        async CSGetBorrowingFormOverdue(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormOverdue(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }

                })

            })

        },
        // 借阅单 查询--详情
        async CSGetBorrowingFormDetails(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormDetails(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }

                })

            })

        },
        // 借阅单 通过
        async CSGetBorrowingFormBtnPass(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormBtnPass(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }

                })

            })

        },
        // 借阅单 驳回
        async CSGetBorrowingFormBtnReject(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormBtnReject(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }

                })

            })

        },
        // 借阅单位
        async getWorkCompany(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetWorkCompany().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }

                })

            })

        },
        //CS借阅单列表-详情-编辑保存
        CSGetBorrowingFormDetailsSave(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormDetailsSave(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                        ElMessage.success(res.msg || "添加成功")
                    } else {
                        ElMessage.error(res.msg || "添加失败")
                        reject(res)
                    }
                })
            })
        },
        //CS借阅单列表-详情-删除
        async CSDeleteBorrowingFormDetails(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSDeleteBorrowingFormDetails(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                        ElMessage.success(res.msg || "删除成功")
                    } else {
                        ElMessage.error(res.msg || "删除失败")
                        reject(res)
                    }
                })
            })
        },
        //打印借阅单详情---生成excel
        async DownloadFormDetailExcel(): Promise<any> {
            return new Promise((resolve, reject) => {
                DownloadFormDetailExcel(this.downloadObj).then((res: any) => {
                    resolve(res)
                })
            })
        },
        //CS获取借阅单列表-已驳回
        async CSGetBorrowingFormReject(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormReject(data).then((res: any) => {
                    if (res.code == 200) {

                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "获取失败")
                    }
                })
            })
        },
        //CS获取借阅单列表-已驳回 详情 新
        async CSGetBorrowingFormDetailsReject(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                CSGetBorrowingFormDetailsReject(data).then((res: any) => {
                    if (res.code == 200) {

                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "获取失败")
                    }
                })
            })
        },
    },

});